package com.oracle.Service;

import com.oracle.Service.impl.AdminService;
import com.oracle.dao.AdminDaoImpl;
import com.oracle.dao.impl.AdminDao;
import com.oracle.pojo.Admin;
import com.oracle.pojo.AdminInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class AdminServiceImpl implements AdminService {

    @Autowired
    public AdminDao adminDao;

    @Override
    public Admin selectAdminByUsername(Admin admin) {
        Admin adminSC = adminDao.selectAdminByUsername(admin);
        if(adminSC==null){
            //如果数据库中没有查到数据,则返回null
            return null;
        }

        if (!adminSC.getPassword().equals(admin.getPassword())){
            //如果从数据库中取出admin的密码与用户的密码不一致，则返回null
            return null;
        }

        //一致则返回admin
       return adminSC;
    }

    @Override
    public AdminInfo selectAdminInfoByMid(Integer mid) {
        return adminDao.selectAdminInfoByMid(mid);
    }

    @Override
    public String updateAdminInfo(AdminInfo adminInfo) {
        String code = adminDao.updateAdminInfo(adminInfo);
        if (code.equals("YES")){
            return "YES";
        }
        return "NO";
    }
}
